1 00:00:00,480 --> 00:00:04,230 And so now we have our shop where we could buy stuff with our points. 2 00:00:04,230 --> 00:00:05,610 Then we have the stuff. 3 00:00:05,610 --> 00:00:09,970 But if we leave the game or if we die, we lose the stuff. 4 00:00:09,990 --> 00:00:11,670 Today we're going to fix that. 5 00:00:11,670 --> 00:00:13,080 So wait for it. 6 00:00:13,080 --> 00:00:14,550 Let me play the game. 7 00:00:14,550 --> 00:00:19,830 I had already bought a pistol and a lemon and now look at that. 8 00:00:20,010 --> 00:00:21,660 I got my pistol. 9 00:00:22,020 --> 00:00:24,900 I got my lemon if I die. 10 00:00:26,710 --> 00:00:26,950 Yeah. 11 00:00:28,740 --> 00:00:30,280 Wait for it. 12 00:00:30,300 --> 00:00:31,150 There we go. 13 00:00:31,170 --> 00:00:31,920 We got it again. 14 00:00:31,920 --> 00:00:34,920 So I do just put it in the backpack when we reset. 15 00:00:34,920 --> 00:00:36,150 But that's fine. 16 00:00:36,180 --> 00:00:37,080 You could just pick it up. 17 00:00:37,080 --> 00:00:38,670 At least you have your stuff. 18 00:00:38,670 --> 00:00:42,630 And if we look at our view output, we don't see any errors. 19 00:00:42,630 --> 00:00:43,970 That's what I like to see. 20 00:00:43,980 --> 00:00:46,500 So let's go ahead and get started on that. 21 00:00:47,880 --> 00:00:53,880 I have my zombie game open and now I need to add the ability to store the things that I bought in my 22 00:00:53,880 --> 00:01:00,480 shop to my data store so that when I die and come back, or if I leave the game and come back, I still 23 00:01:00,480 --> 00:01:01,620 have my items. 24 00:01:01,650 --> 00:01:09,030 Now I could put this storage stuff on my player like I did with Daily Streak, but the items are going 25 00:01:09,030 --> 00:01:10,290 to be more sophisticated. 26 00:01:10,290 --> 00:01:13,020 We're going to have guns, we're going to keep track of ammo. 27 00:01:13,020 --> 00:01:21,810 We may have reload speed changes, We might have a fabulous lemon that has teleportation powers, Cool 28 00:01:21,810 --> 00:01:22,770 stuff like that. 29 00:01:22,770 --> 00:01:25,620 More than just one number, like a daily streak. 30 00:01:25,620 --> 00:01:30,260 So we're going to need an equipment storage manager of some type. 31 00:01:30,270 --> 00:01:39,090 Let's go to our server script service, hit the plus, add a module script, and I'm going to call this 32 00:01:39,990 --> 00:01:44,070 equip storage utils. 33 00:01:45,010 --> 00:01:50,530 Let's change this default module name to equipment. 34 00:01:50,560 --> 00:01:53,260 I'll just say equip utils. 35 00:01:53,290 --> 00:01:59,560 It doesn't have to be the same name as the file name, but if you change it here control C, you have 36 00:01:59,560 --> 00:02:01,000 to change it here. 37 00:02:01,000 --> 00:02:05,380 And these two have to match the the declaration and the return. 38 00:02:06,100 --> 00:02:06,370 All right. 39 00:02:06,370 --> 00:02:15,860 We're going to need another table in here, and I'll just define this locally, local equipment table. 40 00:02:15,880 --> 00:02:17,900 And what do you think that's going to do? 41 00:02:17,930 --> 00:02:20,050 Well, let's put a note so we don't have to guess. 42 00:02:20,290 --> 00:02:31,960 I'm going to say data table that has the equipment info for each player, each player currently playing. 43 00:02:32,370 --> 00:02:33,030 Right. 44 00:02:33,040 --> 00:02:35,500 And we're going to need a few functions. 45 00:02:35,500 --> 00:02:36,580 Let's put a note. 46 00:02:36,610 --> 00:02:44,710 So first thing I think I want to handle is called when purchase. 47 00:02:44,890 --> 00:02:51,520 So we're going to purchase an item and we're going to we're going to store that item data for the player 48 00:02:51,520 --> 00:02:52,870 that purchased the item. 49 00:02:53,590 --> 00:02:58,180 Let's do this function because we're going to we're going to call this from our shop stuff, right? 50 00:02:58,180 --> 00:03:00,310 Our server side shop script. 51 00:03:01,030 --> 00:03:03,790 I'll get this equip utils. 52 00:03:04,120 --> 00:03:04,600 There we go. 53 00:03:04,600 --> 00:03:05,440 Oh my gosh. 54 00:03:05,440 --> 00:03:07,480 Utils colon. 55 00:03:08,290 --> 00:03:15,230 Add item to player's inventory. 56 00:03:15,250 --> 00:03:19,780 We're going to have the player and then we're going to have an item. 57 00:03:19,900 --> 00:03:21,150 How do I spell item? 58 00:03:21,160 --> 00:03:21,640 There he goes. 59 00:03:21,640 --> 00:03:24,520 Item info table. 60 00:03:24,520 --> 00:03:28,330 So we're going to have a table that we're adding to the table, right? 61 00:03:28,330 --> 00:03:29,560 We may have a gun. 62 00:03:29,560 --> 00:03:35,590 We might have six bullets, we might have damage information, we might have a lot of stuff going on 63 00:03:35,590 --> 00:03:37,320 in this equipment that we bought. 64 00:03:37,330 --> 00:03:40,300 So we want to capture all of that information. 65 00:03:40,990 --> 00:03:43,870 And now I'm going to put a comment for my next function. 66 00:03:44,140 --> 00:03:46,090 I'm not filling out these functions yet. 67 00:03:46,090 --> 00:03:47,260 I'm going to get to them. 68 00:03:47,530 --> 00:03:52,900 And this one will be initialized when the player enters the game. 69 00:03:52,900 --> 00:03:53,130 Right. 70 00:03:53,140 --> 00:03:59,320 So I'll say called on initialized initialization. 71 00:03:59,380 --> 00:04:05,410 I spell that right data called on initialization data. 72 00:04:05,680 --> 00:04:11,860 I'll just say initialization when player enters the game. 73 00:04:11,860 --> 00:04:12,160 Right. 74 00:04:12,160 --> 00:04:13,960 So somebody entered the game. 75 00:04:13,960 --> 00:04:18,910 We're going to go to the data store, we're going to get this equipment information, we're going to 76 00:04:18,910 --> 00:04:21,090 store it in our table. 77 00:04:21,100 --> 00:04:25,300 We'll say, function, equip, utils. 78 00:04:25,300 --> 00:04:30,670 I'm going to call this update player. 79 00:04:32,210 --> 00:04:35,390 With DB info. 80 00:04:36,470 --> 00:04:36,710 All right. 81 00:04:36,710 --> 00:04:40,850 So we'll have all of the equipment data is going to be in here. 82 00:04:40,850 --> 00:04:42,560 This is when they're entering the game. 83 00:04:42,560 --> 00:04:45,470 Anything we save off from here, we haven't done that yet. 84 00:04:45,470 --> 00:04:49,300 From here is going to be put into this data. 85 00:04:49,340 --> 00:04:51,260 We're going to parse it out right here. 86 00:04:51,470 --> 00:04:51,690 Right. 87 00:04:51,740 --> 00:04:54,920 That's going to be the meat of the of the script. 88 00:04:55,190 --> 00:04:55,430 All right. 89 00:04:55,430 --> 00:04:58,190 We're going to need what else are we going to need? 90 00:04:58,190 --> 00:05:04,460 Are we're going to put the data inside the table, but then we have to actually equip the player. 91 00:05:04,460 --> 00:05:04,940 Right. 92 00:05:04,940 --> 00:05:06,260 So we'll say. 93 00:05:07,400 --> 00:05:22,160 Equip player data is whoops, data is already in table, but player doesn't have it. 94 00:05:22,610 --> 00:05:30,620 All right, so we've got our function here and then we'll do equip utils and I'll just call this equip 95 00:05:30,620 --> 00:05:31,370 player. 96 00:05:32,480 --> 00:05:33,530 I make sense. 97 00:05:33,530 --> 00:05:34,700 Oh, we'll pass the player in. 98 00:05:34,700 --> 00:05:38,960 We'll be able to find all the information is already in our equipment table. 99 00:05:38,960 --> 00:05:42,950 And one last very easy function, Right? 100 00:05:42,950 --> 00:05:48,410 I need to remove the player data from this table when they leave the game. 101 00:05:48,410 --> 00:05:53,630 Else it's just going to get bigger and bigger and bigger until we we restart the server. 102 00:05:53,630 --> 00:06:04,670 So I'll say when player is removed from game, remove info from table. 103 00:06:04,670 --> 00:06:08,840 Now you wouldn't even notice this growth unless you had a very popular game. 104 00:06:08,840 --> 00:06:14,450 If you had thousands of people playing and the server was running for a period of time, you start bogging 105 00:06:14,450 --> 00:06:15,290 it down. 106 00:06:15,410 --> 00:06:15,710 Right? 107 00:06:15,710 --> 00:06:18,620 But you wouldn't notice that you wouldn't notice this right away. 108 00:06:18,950 --> 00:06:25,340 I'll say equip utils remove player. 109 00:06:25,340 --> 00:06:30,410 So this is going to remove the data for the player from our table. 110 00:06:31,190 --> 00:06:32,600 That's pretty cool. 111 00:06:32,600 --> 00:06:37,880 All right, now we can go ahead and start populating this out a little bit and seeing where we're going 112 00:06:37,880 --> 00:06:39,350 to call this stuff.